Imports System.Data.SqlClient
Public Class DataServices
    Dim m_Connection As New SqlConnection
    Dim m_DataAdapter As New SqlDataAdapter
    Dim m_Command As New SqlCommand
    Public Sub OpenConnection()
        ob_cnn.Open()
    End Sub

    Public Sub CloseConnection()
        ob_cnn.Close()
    End Sub

    Public Function ExecuteQuery(ByVal sql As String) As DataTable
        Dim dt As New DataTable()
        ob_cnn.Open()
        m_DataAdapter = New SqlDataAdapter(sql, ob_cnn)

        m_DataAdapter.Fill(dt)

        If (dt.Rows.Count = 0) Then
            'Return Nothing
        End If

        ob_cnn.Close()
        Return dt
    End Function

    Public Sub ExecuteNonQuery(ByVal sql As String)
        ob_cnn.Open()
        m_Command = New SqlCommand(sql, ob_cnn)
        m_Command.CommandType = CommandType.Text
        m_Command.ExecuteNonQuery()

        ob_cnn.Close()
    End Sub
    Public Sub ExcetureDML(ByVal sql As String)
        'Mo ket noi du lieu
        ob_cnn.Open()

        'cap nhat du lieu
        m_Command = New SqlCommand(sql, ob_cnn)
        m_Command.CommandType = CommandType.Text
        m_Command.ExecuteNonQuery()

        'Dong ket noi du lieu
        ob_cnn.Close()

    End Sub
End Class
